# https://www.bilibili.com/video/BV1W7411G7wP/?p=19&spm_id_from=pageDriver&vd_source=8bd7b24b38e3e12c558d839b352b32f4
# 19. 叩开统计的大门把函数一网打尽（求和、求平均、统计导引）
import pandas as pd

students = pd.read_excel('../resources/input_py_tools/019/Students.xlsx')
print(students)

# 求学生三次考试的总分和平均分
temp = students[['Test_1', 'Test_2', 'Test_3']]
#print(temp)
# 按列统计的总分 axis=0
#col_sum = temp.sum()
#print(col_sum)
row_sum = temp.sum(axis=1)
row_mean = temp.mean(axis=1)
# print(row_sum)
# print(row_mean)
# 加入到students
students['Total'] = row_sum
students['Average'] = row_mean
print(students)

# 班级汇总 平均分
col_mean = students[['Test_1', 'Test_2', 'Test_3', 'Total', 'Average']].mean()
print(type(col_mean))
print(col_mean)
col_mean['Name'] = 'Summary'
# 加入到students
students = students.append(col_mean, ignore_index=True)
# FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
#   students.append(col_mean, ignore_index=True)

# 查看结果
print(students)

# pandas api
# https://pandas.pydata.org/pandas-docs/stable/reference/index.html
# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.sum.html
# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.mean.html
# 主要值
# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.mode.html
# 标准差
# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.std.html
# 方差
# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.var.html